package cn.ffcs.uec.outStaff.component;

import java.io.FileInputStream;
import java.net.URLEncoder;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import javax.servlet.http.HttpServletRequest;

import org.springframework.context.annotation.Scope;
import org.springframework.stereotype.Controller;
import org.zkoss.util.media.Media;
import org.zkoss.web.servlet.Servlets;
import org.zkoss.zk.ui.Components;
import org.zkoss.zk.ui.Executions;
import org.zkoss.zk.ui.IdSpace;
import org.zkoss.zk.ui.event.Event;
import org.zkoss.zk.ui.event.EventListener;
import org.zkoss.zk.ui.event.ForwardEvent;
import org.zkoss.zk.ui.event.UploadEvent;
import org.zkoss.zkplus.databind.BindingListModelList;
import org.zkoss.zul.Div;
import org.zkoss.zul.Filedownload;
import org.zkoss.zul.ListModel;
import org.zkoss.zul.Messagebox;
import org.zkoss.zul.Window;

import cn.ffcs.raptornuke.plugin.common.zk.util.ZkUtil;
import cn.ffcs.uec.common.util.PermissionUtil;
import cn.ffcs.uec.common.vo.UecBdDefdoc;
import cn.ffcs.uec.outStaff.component.bean.UecOutStaffTalentTeamListboxBean;
import cn.ffcs.uec.outStaff.constant.UecOutStaffConstants;
import cn.ffcs.uec.outStaff.model.UecOutStaffInfo;
import cn.ffcs.uec.recordsApproval.constant.ApprovalConstants;
import cn.ffcs.uec.recordsApproval.util.ApprovalUtil;
import cn.ffcs.uec.staff.manager.UecTalentTeamManager;
import cn.ffcs.uec.staff.manager.UecTrialManager;
import cn.ffcs.uec.staff.model.UecTalentTeam;
import cn.ffcs.uec.staff.model.UecTrial;
import cn.ffcs.uom.common.constants.BaseUnitConstants;
import cn.ffcs.uom.common.model.DefaultDaoFactory;
import cn.ffcs.uom.common.util.ApplicationContextUtil;
import cn.ffcs.uom.common.util.DateUtil;
import cn.ffcs.uom.common.util.FileUtil;
import cn.ffcs.uom.common.util.IPortletInfoProvider;
import cn.ffcs.uom.common.util.ListboxUtils;
import cn.ffcs.uom.common.util.PlatformUtil;
import cn.ffcs.uom.common.util.StrUtil;
import cn.ffcs.uom.common.vo.PageInfo;
import cn.ffcs.uom.common.zul.PubUtil;
import lombok.Getter;
import lombok.Setter;

/**
 * @Title:专业人才队伍信息 CRUD插件
 * @Description:
 * @Copyright: FFCS（C） 2017
 * @Company: FFCS
 * @since JDK1.6
 */
@Controller
@Scope("prototype")
public class UecOutStaffTalentTeamListboxExt extends Div implements IdSpace {

	private static final long serialVersionUID = -5811398149406451671L;
	/**
	 * 人员基本信息功能 查询出的实体对象
	 */
	private UecOutStaffInfo uecOutStaffInfo;
	/**
	 * 对应页面上的bean
	 */
	private UecOutStaffTalentTeamListboxBean bean = new UecOutStaffTalentTeamListboxBean();

	private UecTrialManager uecTrialManager = (UecTrialManager) ApplicationContextUtil
			.getBean("uecTrialManager");
	/**
	 * 专业人才队伍
	 */
	private UecTalentTeam uecTalentTeam;
	/**
	 * 上传文件
	 */
	private Media media;

	/**
	 * 存放上传数据
	 */
	private List<UecTalentTeam> talentTeams = new ArrayList<UecTalentTeam>();

	private static final int TOTAL_COLUMN = 16;

	private UecTalentTeamManager uecTalentTeamManager = (UecTalentTeamManager) ApplicationContextUtil
			.getBean("uecTalentTeamManager");

	@Getter
	@Setter
	private IPortletInfoProvider portletInfoProvider;

	public UecOutStaffTalentTeamListboxExt() {
		Executions.createComponents(
				UecOutStaffConstants.UEC_OUT_STAFF_TALANTTEAM_EXT_LISTBOX_ZUL,
				this, null);
		Components.wireVariables(this, bean);
		Components.addForwards(this, this, '$');

		this.addForward(UecOutStaffConstants.ON_UEC_OUT_STAFF_TALENTTEAM_QUERY,
				this,
				UecOutStaffConstants.ON_UEC_OUT_STAFF_TALENTTEAM_QUERY_RESPONSE);

		this.addForward(UecOutStaffConstants.ON_CLEAN_UEC_OUT_STAFF_TALENTTEAM,
				this,
				UecOutStaffConstants.ON_CLEAN_UEC_OUT_STAFF_TALENTTEAM_RESPONSE);

	}

	/**
	 * 初始化
	 */
	public void onCreate() {
		this.setButtonValid(false, false, false, false, false, false);
	}

	/**
	 * 选择查询记录
	 * 
	 * @throws Exception
	 */
	public void onSelectUecTalentTeamList() throws Exception {
		if (this.bean.getUecTalentTeamListbox().getSelectedCount() > 0) {
			uecTalentTeam = (UecTalentTeam) bean.getUecTalentTeamListbox()
					.getSelectedItem().getValue();
		}
	}

	/**
	 * 人员基本信息功能，抛出事件， 事件监听
	 * 
	 * @param event
	 */
	public void onUecOutStaffTalentTeamQueryResponse(ForwardEvent event) {
		uecOutStaffInfo = (UecOutStaffInfo) event.getOrigin().getData();
		if (null != uecOutStaffInfo) {
            //设置操作按钮，非盟市主管不可操作按钮
            if(PermissionUtil.isNoMainOutStaff()) {
                this.setButtonValid(false, false, false, false,false,false);
            }else {
                this.setButtonValid(true, true, true, true, true, false);
            }
			uecTalentTeam = new UecTalentTeam();
			uecTalentTeam.setStaffId(uecOutStaffInfo.getOutStaffId());
			uecTalentTeam.setNmStaffType(BaseUnitConstants.NM_OUT_STAFF_TYPE);		
			this.onQueryUecTalentTeam();
		}
	}

	/**
	 * 清楚变量事件
	 * 
	 * @param event
	 */
	public void onCleanUecOutStaffTalentTeamResponse(ForwardEvent event) {
		clearVariable();
		uecOutStaffInfo = null;
		ListboxUtils.clearListbox(this.bean.getUecTalentTeamListbox());
		this.bean.getUecTalentTeamListboxPaging().setTotalSize(1);
		this.setButtonValid(false, false, false, false, false, false);
	}

	/**
	 * 设置按钮
	 * 
	 * @param canAdd
	 * @param candel
	 */
	private void setButtonValid(boolean canDownload, boolean canUpload,
			boolean canView, boolean canAdd, boolean canEdit, boolean candel) {
		this.bean.getDownloadButton().setDisabled(!canDownload);
		this.bean.getUploadButton().setDisabled(!canUpload);
		this.bean.getViewButton().setDisabled(!canView);
		this.bean.getAddButton().setDisabled(!canAdd);
		this.bean.getEditButton().setDisabled(!canEdit);
		this.bean.getDelButton().setDisabled(!candel);
	}

	/**
	 * 查询按钮
	 */
	public void onQueryUecTalentTeam() {
		this.bean.getUecTalentTeamListboxPaging().setActivePage(0);
		this.onQueryUecTalentTeamList();
	}

	/**
	 * 重置按钮
	 */
	public void onReset() {
		cn.ffcs.uom.common.util.PubUtil.clearComponent(this);
	}

	/**
	 * 下载模版
	 */
	@SuppressWarnings("deprecation")
	public void onDownloadTemplate() {
		try {
			String charset = "UTF-8";
			// 服务器文件名
			String fileName = "uecOutStaffTalentTeam_template.xls";
			// 编码后文件名
			String encodedName = null;
			encodedName = URLEncoder.encode(fileName, charset);
			// 将空格替换为+号
			encodedName = encodedName.replace("%20", "+");
			HttpServletRequest httpRequest = (HttpServletRequest) Executions
					.getCurrent().getNativeRequest();
			// 解决ie6 bug 或者是火狐浏览器
			if (encodedName.length() > 150 || Servlets.isGecko(httpRequest)
					|| Servlets.isGecko3(httpRequest)) {
				encodedName = new String(fileName.getBytes(charset),
						"ISO8859-1");
			}
			Filedownload.save(
					new FileInputStream(httpRequest
							.getRealPath("/pages_nmg/uec_outStaff/doc/"
									+ fileName)), "application/octet-stream",
					encodedName);
		} catch (Exception e) {
			ZkUtil.showError("下载专业人才队伍信息导入模版失败。", "系统提示");
		}
	}

	/**
	 * 文件上传 导入员工
	 * 
	 * @param event
	 * @throws Exception
	 */
	public void onUpload$uploadButton(final ForwardEvent forwardEvent)
			throws Exception {

		// 清除变量
		talentTeams.clear();

		UecTrial qryUecTrial = UecTrial.newInstance();
		qryUecTrial.setStaffId(uecOutStaffInfo.getOutStaffId());
		qryUecTrial.setNmStaffType(BaseUnitConstants.NM_OUT_STAFF_TYPE);
		qryUecTrial = uecTrialManager.findUecTrial(qryUecTrial);
		if (null == qryUecTrial) {
			ZkUtil.showError("此人未入职,请先执行入职操作", "温馨提示");
			return;
		}

		String tips = "";
		if (!ApprovalUtil.getActivityFlag()) {
			tips = "确认批量导入文件？导入后将直接保存到人员信息！";
		} else {
			tips = "确认批量导入文件？导入后将直接发起流程！";
		}
		Messagebox.show(tips, "输入确认", Messagebox.OK | Messagebox.CANCEL,
				Messagebox.QUESTION, new EventListener() {
					@Override
					public void onEvent(Event event) throws Exception {
						if (((Integer) event.getData()).intValue() == Messagebox.OK) {
							bean.getUecTalentTeamListbox().clearSelection();

							media = ((UploadEvent) forwardEvent.getOrigin())
									.getMedia();
							if (null == media) {
								ZkUtil.showError("请选择要上传的文件!", "系统提示");
								return;
							}
							String fileName = media.getName();
							if (fileName.endsWith(".xls")
									|| fileName.endsWith(".xlsx")) {
								// readsUpLoadFile();
							} else {
								ZkUtil.showError(
										"导入的文件必须是以.xls或.xlsx结尾的EXCEL文件!",
										"系统提示");
								return;
							}
							String[][] objArray = FileUtil.readExcel(media, 1,
									1);
							if (objArray == null || objArray.length == 0) {
								ZkUtil.showError("导入文件没有数据！", "错误信息");
								return;
							}
							setDataToRows(objArray, fileName);
						} else {
							return;
						}
					}
				});

	}

	private void setDataToRows(String[][] data, String fileName) {

		talentTeams.clear();
		String[] row = null;
		boolean isUpload = true;
		for (int i = 0; i < data.length; i++) {
			row = data[i];
			if (row.length != TOTAL_COLUMN + 1) {
				ZkUtil.showError("导入文件数据不正确！", "错误信息");
				return;
			}

			UecTalentTeam talentTeam = UecTalentTeam.newInstance();
			for (int j = 0; j < TOTAL_COLUMN; j++) {

				switch (j) {
				// 专业人才名称
				case 0:
					if (null == data[i][j]) {
						ZkUtil.showError("专业人才名称为空！", "错误提示");
						isUpload = false;
						return;
					}
					StringBuilder glbdef1Builder = new StringBuilder(
							" select * from uec_bd_defdoc t where t.pk_defdoclist = '1001A1100000001Z6UEN' "
									+ " and t.name = ? ");
					List<Object> glbdef1Params = new ArrayList<Object>();
					glbdef1Params.add(data[i][j]);
					UecBdDefdoc uecBdDefdoc = DefaultDaoFactory.getDefaultDao()
							.jdbcFindObject(glbdef1Builder.toString(),
									glbdef1Params, UecBdDefdoc.class);
					if (StrUtil.isNullOrEmpty(uecBdDefdoc)) {
						ZkUtil.showError("专业人才名称填写不正确!", "错误提示");
						return;
					}
					talentTeam.setGlbdef1(uecBdDefdoc.getPkDefdoc());
					break;
				// 专业人才等级
				case 1:
					if (StrUtil.isNullOrEmpty(data[i][j])) {
						ZkUtil.showError("专业人才等级为空！", "错误提示");
						isUpload = false;
						return;
					}
					StringBuilder glbdef2Builder = new StringBuilder(
							" select * from uec_bd_defdoc t where t.pk_defdoclist = '1001A110000000000515' "
									+ " and t.name = ? ");
					List<Object> glbdef2Params = new ArrayList<Object>();
					glbdef2Params.add(data[i][j]);
					uecBdDefdoc = DefaultDaoFactory.getDefaultDao()
							.jdbcFindObject(glbdef2Builder.toString(),
									glbdef2Params, UecBdDefdoc.class);
					if (StrUtil.isNullOrEmpty(uecBdDefdoc)) {
						ZkUtil.showError("专业人才等级填写不正确!", "错误提示");
						return;
					}
					talentTeam.setGlbdef2(uecBdDefdoc.getPkDefdoc());
					break;
				// 专业工作年度考核结果
				case 2:
					if (StrUtil.isNullOrEmpty(data[i][j])) {
						ZkUtil.showError("专业工作年度考核结果为空！", "错误提示");
						isUpload = false;
						return;
					}
					StringBuilder glbdef3Builder = new StringBuilder(
							" select * from uec_bd_defdoc t where t.pk_defdoclist = '1001Z71000000000DCPT' "
									+ " and t.name = ? ");
					List<Object> glbdef3Params = new ArrayList<Object>();
					glbdef3Params.add(data[i][j]);
					uecBdDefdoc = DefaultDaoFactory.getDefaultDao()
							.jdbcFindObject(glbdef3Builder.toString(),
									glbdef3Params, UecBdDefdoc.class);
					if (StrUtil.isNullOrEmpty(uecBdDefdoc)) {
						ZkUtil.showError("专业工作年度考核结果填写不正确!", "错误提示");
						return;
					}
					talentTeam.setGlbdef3(uecBdDefdoc.getPkDefdoc());
					break;
				// 专家津贴金额
				case 3:
					if (StrUtil.isNullOrEmpty(data[i][j])) {
						ZkUtil.showError("专家津贴金额为空！", "错误提示");
						isUpload = false;
						return;
					}
					try {
						Double.valueOf(data[i][j]);
					} catch (NumberFormatException e) {
						ZkUtil.showError("专家津贴格式不正确！", "错误提示");
						isUpload = false;
						e.printStackTrace();
						return;
					}
					talentTeam.setGlbdef4(data[i][j]);
					break;
				// 特殊年金金额
				case 4:
					if (!StrUtil.isNullOrEmpty(data[i][j])) {
						try {
							Double.valueOf(data[i][j]);
						} catch (NumberFormatException e) {
							ZkUtil.showError("特殊年金金额格式不正确！", "错误提示");
							isUpload = false;
							e.printStackTrace();
							return;
						}
					}
					talentTeam.setGlbdef5(data[i][j]);
					break;
				// 股票增值权
				case 5:
					if (StrUtil.isNullOrEmpty(data[i][j])) {
						ZkUtil.showError("股票增值权为空！", "错误提示");
						isUpload = false;
						return;
					}
					talentTeam.setGlbdef6(data[i][j]);
					break;
				// 开始时间
				case 6:
					if (StrUtil.isNullOrEmpty(data[i][j])) {
						ZkUtil.showError("开始时间为空！", "错误提示");
						isUpload = false;
						return;
					}
					try {
						new SimpleDateFormat("yyyy-MM-dd").parse(data[i][j]);
					} catch (ParseException e) {
						ZkUtil.showError("开始时间格式不正确！", "错误提示");
						isUpload = false;
						e.printStackTrace();
						return;
					}
					talentTeam.setBegindate(data[i][j]);
					break;
				// 结束时间
				case 7:
//					if (StrUtil.isNullOrEmpty(data[i][j])) {
//						ZkUtil.showError("结束时间为空！", "错误提示");
//						isUpload = false;
//						return;
//					}
					try {
						if (!StrUtil.isNullOrEmpty(data[i][j])) {
							new SimpleDateFormat("yyyy-MM-dd").parse(data[i][j]);
						}
					} catch (ParseException e) {
						ZkUtil.showError("结束时间格式不正确！", "错误提示");
						isUpload = false;
						e.printStackTrace();
						return;
					}
					talentTeam.setEnddate(data[i][j]);
					break;
				// 人才类型
				case 8:
					if (StrUtil.isNullOrEmpty(data[i][j])) {
						ZkUtil.showError("人才类型为空！", "错误提示");
						isUpload = false;
						return;
					}
					if ("实操".equals(data[i][j])) {
						talentTeam.setGlbdef10("1");
					} else {
						talentTeam.setGlbdef10("2");
					}
					break;
				// 第一年考核
				case 9:
					if (StrUtil.isNullOrEmpty(data[i][j])) {
						ZkUtil.showError("第一年考核为空！", "错误提示");
						isUpload = false;
						return;
					}
					talentTeam.setGlbdef11(data[i][j]);
					break;
				// 第二年考核
				case 10:
					if (StrUtil.isNullOrEmpty(data[i][j])) {
						ZkUtil.showError("第二年考核为空！", "错误提示");
						isUpload = false;
						return;
					}
					talentTeam.setGlbdef12(data[i][j]);
					break;
				// 聘任状态
				case 11:
					if (StrUtil.isNullOrEmpty(data[i][j])) {
						ZkUtil.showError("聘任状态为空！", "错误提示");
						isUpload = false;
						return;
					}
					if ("在聘".equals(data[i][j])) {
						talentTeam.setGlbdef13("1001A1100000001SVL1S");
					}
					if ("退出".equals(data[i][j])) {
						talentTeam.setGlbdef13("1001A1100000001SVL1T");
					}
					break;
				// 退出时间
				case 12:
//					if (StrUtil.isNullOrEmpty(data[i][j])) {
//						ZkUtil.showError("退出时间为空！", "错误提示");
//						isUpload = false;
//						return;
//					}
					try {
						new SimpleDateFormat("yyyy-MM-dd").parse(data[i][j]);
					} catch (ParseException e) {
						ZkUtil.showError("退出时间格式不正确！", "错误提示");
						isUpload = false;
						e.printStackTrace();
						return;
					}
					talentTeam.setGlbdef14(data[i][j]);
					break;
				// 退出原因
				case 13:
					talentTeam.setGlbdef15(data[i][j]);
					break;
				// 子专业
				case 14:
					if (StrUtil.isNullOrEmpty(data[i][j])) {
						ZkUtil.showError("子专业为空！", "错误提示");
						isUpload = false;
						return;
					}
					StringBuilder glbdef9Builder = new StringBuilder(
							" select * from uec_bd_defdoc t where t.pk_defdoclist = '1001A1100000001Z6UEN' "
									+ " and t.name = ? ");
					List<Object> glbdef9Params = new ArrayList<Object>();
					glbdef9Params.add(data[i][j]);
					uecBdDefdoc = DefaultDaoFactory.getDefaultDao()
							.jdbcFindObject(glbdef9Builder.toString(),
									glbdef9Params, UecBdDefdoc.class);
					if (StrUtil.isNullOrEmpty(uecBdDefdoc)) {
						ZkUtil.showError("子专业填写不正确!", "错误提示");
						return;
					}
					talentTeam.setGlbdef9(uecBdDefdoc.getPkDefdoc());
					break;
				// 是否生效
				case 15:
					if (StrUtil.isNullOrEmpty(data[i][j])) {
						ZkUtil.showError("是否生效为空！", "错误提示");
						isUpload = false;
						return;
					}
					if ("是".equals(data[i][j])) {
						talentTeam.setGlbdef8("Y");
					}
					if ("否".equals(data[i][j])) {
						talentTeam.setGlbdef8("N");
					}
					break;
				default:
					break;
				}

			}
			if (!isUpload) {
				return;
			}

			talentTeam.setStaffId(uecOutStaffInfo.getOutStaffId());
			if (StrUtil.isNullOrEmpty(PlatformUtil.getCurrentUser())) {
				ZkUtil.showError("当前用户不存在！", "错误提示");
				return;
			}
			talentTeam
					.setCreator(PlatformUtil.getCurrentUser().getScreenName());
			talentTeam.setCreationtime(DateUtil.getCurrenDate());

			talentTeam.setDr(0L);
			talentTeam.setLastflag("Y");

			talentTeam.setNmStaffType(BaseUnitConstants.NM_OUT_STAFF_TYPE);

			talentTeams.add(talentTeam);
		}

		if (null != talentTeams) {
			ListModel list = new BindingListModelList(talentTeams, true);
			this.bean.getUecTalentTeamListbox().setModel(list);
			this.bean.getUecTalentTeamListboxPaging().setTotalSize(1);
			if (ApprovalUtil.getActivityFlag()) {
				String formTheme = "盟市外包人员专业人才申请流程";
				String procInstId = null;
				for (UecTalentTeam talentTeam : talentTeams) {

					// 发起流程 uec_talent_team 新增一条记录
					// 判断该人员是否在审状态，如果是在审状态不允许再次发起此流程
					// boolean isOnApproval =
					// ApprovalUtil.isOnApproval(procDefId,
					// uecOutStaffInfo.getOutStaffId());
					// if(isOnApproval) {
					// ZkUtil.showError("在审状态不允许发起！", "错误提示");
					// return;
					// }

					Long outStaffId = uecOutStaffInfo.getOutStaffId();

					talentTeam.addStatusCdIS3();
					Long talentTeamId = talentTeam.getTalentTeamId();

					if (StrUtil.isNullOrEmpty(PlatformUtil.getCurrentUser())) {
						ZkUtil.showError("当前登录用户不存在!", "错误提示");
						return;
					}
					String currentName = PlatformUtil.getCurrentUser()
							.getScreenName();

					String startFlowJson = "{" + "formTheme: '"
							+ formTheme
							+ "',"
							+ " formContent: '专业人才人员:"
							+ uecOutStaffInfo.getPsnName()
							+ "',"
							+ " procDefId: '"
							+ ApprovalConstants.OUT_STAFF_TALENT_TEAM_PROC_DEF_ID
							+ "'," + " urgent: '1'," + " atiActCategoryId: '"
							+ ApprovalConstants.MODIFICATION_CATEGORY_ID + "',"
							+ " procDefKey: '"
							+ ApprovalUtil.OUT_STAFF_TALENT_TEAM_EDIT + "',"
							+ " formSender: '" + currentName + "',"
							+ " primaryId: '{" + "uec_out_staff_info_his:"
							+ outStaffId + ",uec_out_staff_info:" + outStaffId
							+ ",uec_talent_team:" + talentTeamId + "'}";

					try {
						procInstId = ApprovalUtil.startApproval(startFlowJson);
					} catch (Exception e) {
						// 流程发起失败 数据改为失效
						talentTeam.removeOnly();
						onReset();
						ZkUtil.showError("流程发起失败！", "错误提示");
						e.printStackTrace();
					}

					if (StrUtil.isNullOrEmpty(procInstId)) {
						talentTeam.removeOnly();
						onReset();
						ZkUtil.showError("流程发起失败！", "错误提示");
						return;
					}
					// 第一审批人如果是发起人直接到人力审批环节
					ApprovalUtil.isCurrentAssignNames(procInstId);

				}
				ApprovalUtil.showNextAssignee(procInstId, formTheme);
			} else {
				for (UecTalentTeam uecTalentTeam : talentTeams) {
					uecTalentTeam.addOnly();
				}
				ZkUtil.showInformation("批量导入专业人才队伍信息已保存成功!", "温馨提示");
			}

		}

	}

	/**
	 * 查看按钮
	 * 
	 * @throws Exception
	 * @throws InterruptedException
	 */
	public void onViewUecTalentTeam() throws Exception, InterruptedException {
		if (uecTalentTeam.getId() != null) {
			Map<String, Object> map = new HashMap<String, Object>();
			map.put("opType", "view");
			map.put("uecTalentTeam", uecTalentTeam);
			Window window = (Window) Executions.createComponents(
					UecOutStaffConstants.UEC_OUT_STAFF_TALANTTEAM_EDIT_ZUL,
					this, map);
			window.doModal();
			window.addEventListener("onOK", new EventListener() {
				@Override
				public void onEvent(Event event) throws Exception {
					if (event.getData() != null) {
						//
					}
				}
			});
		} else {
			ZkUtil.showError("请选中要查看的记录", "提示信息");
		}
	}

	/**
	 * 新增按钮
	 * 
	 * @throws Exception
	 * @throws
	 */
	public void onAddUecTalentTeam() throws Exception {
		if (null != uecOutStaffInfo) {
			Map<String, Object> map = new HashMap<String, Object>();
			map.put("opType", "add");
			map.put("uecOutStaffInfo", uecOutStaffInfo);
			Window window = (Window) Executions.createComponents(
					UecOutStaffConstants.UEC_OUT_STAFF_TALANTTEAM_EDIT_ZUL,
					this, map);
			window.doModal();
			window.addEventListener("onOK", new EventListener() {
				@Override
				public void onEvent(Event event) throws Exception {
					if (event.getData() != null) {
						// 新增或修改完成后，列表从数据库更新
						uecTalentTeam = (UecTalentTeam) event.getData();
						onQueryUecTalentTeamList();
					}
				}
			});
		}
	}

	/**
	 * 编辑按钮
	 * 
	 * @throws Exception
	 * @throws InterruptedException
	 */
	public void onEditUecTalentTeam() throws Exception, InterruptedException {
		if (uecTalentTeam.getId() != null) {
			Map<String, Object> map = new HashMap<String, Object>();
			map.put("opType", "edit");
			map.put("uecTalentTeam", uecTalentTeam);
			Window window = (Window) Executions.createComponents(
					UecOutStaffConstants.UEC_OUT_STAFF_TALANTTEAM_EDIT_ZUL,
					this, map);
			window.doModal();
			window.addEventListener("onOK", new EventListener() {
				@Override
				public void onEvent(Event event) throws Exception {
					if (event.getData() != null) {
						// 新增或修改完成后，列表从数据库更新
						uecTalentTeam = (UecTalentTeam) event.getData();
						onQueryUecTalentTeamList();
					}
				}
			});

		} else {
			ZkUtil.showError("请选中要编辑的记录", "提示信息");
			return;
		}
	}

	/**
	 * 删除按钮
	 */
	public void onDelUecTalentTeam() {
		if (uecTalentTeam.getId() != null) {
			ZkUtil.showQuestion("确定要删除吗?", "提示信息", new EventListener() {
				public void onEvent(Event event) throws Exception {
					Integer result = (Integer) event.getData();
					if (result == Messagebox.OK) {
						uecTalentTeam.removeOnly();
						PubUtil.reDisplayListbox(
								bean.getUecTalentTeamListbox(), uecTalentTeam,
								"del");
						uecTalentTeam = null;
					}
				}
			});
		} else {
			ZkUtil.showError("请选中要删除的记录", "提示信息");
			return;
		}
	}

	/**
	 * 翻页
	 */
	public void onUecTalentTeamListboxPaging() {
		this.onQueryUecTalentTeamList();
	}

	/**
	 * 清除变量
	 */
	public void clearVariable() {
		uecTalentTeam = null;
	}

	/**
	 * 查询
	 */
	public void onQueryUecTalentTeamList() {
		if (null != uecTalentTeam) {
			PageInfo pageInfo = uecTalentTeamManager
					.queryPageInfoByUecTalentTeam(uecTalentTeam,
							this.bean.getUecTalentTeamListboxPaging()
									.getActivePage() + 1, this.bean
									.getUecTalentTeamListboxPaging()
									.getPageSize());
			ListModel list = new BindingListModelList(pageInfo.getDataList(),
					true);
			this.bean.getUecTalentTeamListbox().setModel(list);
			this.bean.getUecTalentTeamListboxPaging().setTotalSize(
					pageInfo.getTotalCount());
		}
	}

}
